<%@page import="dao.UserManager"%>
<%@page import="model.*"%>
<%@page import="java.util.List"%>
<%@page import="dao.ItemManager"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%@include file='home.jsp'%>
	<%
		ItemManager manager = new ItemManager();
		List<BorrowedItem> borrowedItems = manager
				.fetchBorrowedItemsBySelf(user.getUsername());
		if (borrowedItems != null && borrowedItems.size() > 0) {
	%>
	<h3>Borrowed items by self</h3>
	<table border=1>
		<tr>
			<th>ID</th>
			<th>Title</th>
			<th>Author</th>
			<th>Published</th>
			<th>Type</th>
			<th>Owner</th>
			<th>Owner's workplace</th>
			<th>Borrow date</th>
			<th>Exp. return date</th>
		</tr>
		<%
			for (BorrowedItem borrowedItem : borrowedItems) {
					Item item = borrowedItem.getItem();
					User owner = UserManager.getUser(item.getOwner());
					String workplace = (owner != null) ? owner.getWorkplace() : "";
		%>
		<tr>
			<td><%=item.getId()%></td>
			<td><%=item.getTitle()%></td>
			<td><%=item.getAuthor()%></td>
			<td><%=item.getPublishDate()%></td>
			<td><%=item.getType()%></td>
			<td><%=item.getOwner()%></td>
			<td><%=workplace%></td>
			<td><%=borrowedItem.getBorrowDate()%></td>
			<td><%=borrowedItem.getExpectedReturnDate()%></td>
		</tr>
		<%
			}
		%>
	</table>

	<%
		}
		else{
			out.println("<h3>You have no borrowed items yet.</h3>");
		}
	%>
</body>
</html>